﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Blog.Huge.Core;
using Blog.Huge.Core.DataInterfaces;
using NHibernate;
using NHibernate.Criterion;
using SharpArch.Data.NHibernate;

namespace Blog.Huge.Data
{
    public class PostRepository:Repository<Post>,IPostRepository
    {
        public List<Post> FindAllMatching(string filter)
        {
            ICriteria criteria = Session.CreateCriteria(typeof (Post))
                .Add(Expression.Or(
                        Expression.InsensitiveLike("Content", filter, MatchMode.Anywhere)
                        , Expression.InsensitiveLike("Title", filter, MatchMode.Anywhere)))
                .AddOrder(new NHibernate.Criterion.Order("Title", true));
            return criteria.List<Post>() as List<Post>;
        }
    }
}
